<template>
	<view class="m-input-view">
		<input :focus="focus" :type="inputType" :value="value" @input="onInput" class="m-input-input" :placeholder="placeholder"
		 :password="type==='password'&&!showPassword" @focus="onFocus" @blur="onBlur" :maxlength="maxlength" />
		<!-- 优先显示密码可见按钮 -->
		<!-- <view v-if="clearable&&!displayable&&value.length" class="m-input-icon">
			<image src="../static/img/ic_login_unfold.png" ></image>
		</view> -->
		
		<view v-if="clearable&&!displayable&&value.length" class="m-input-icon">
			<image src="../static/img/ic_login_delete.png"  @click="clear"></image>
		</view>
		
		<view v-if="displayable" class="m-input-icon">
			<image src="../static/img/ic_login_attention_forbid.png"  @click="display" v-if="showPassword"></image>
			<image src="../static/img/attention_fill.png"  @click="display"  v-if="!showPassword"></image>
		</view>
		
	</view>
</template>

<script>
	import mIcon from './m-icon/m-icon.vue'

	export default {
		components: {
			mIcon
		},
		props: {
			/**
			 * 输入类型
			 */
			type: String,
			/**
			 * 值
			 */
			value: String,
			/**
			 * 占位符
			 */
			placeholder: String,
			/**
			 * 占位符
			 */
			maxlength: String,
			/**
			 * 是否显示清除按钮
			 */
			clearable: {
				type: [Boolean, String],
				default: false
			},
			/**
			 * 是否显示密码可见按钮
			 */
			displayable: {
				type: [Boolean, String],
				default: false
			},
			/**
			 * 自动获取焦点
			 */
			focus: {
				type: [Boolean, String],
				default: false
			}
		},
		model: {
			prop: 'value',
			event: 'input'
		},
		data() {
			return {
				/**
				 * 显示密码明文
				 */
				showPassword: false,
				/**
				 * 是否获取焦点
				 */
				isFocus: false
			}
		},
		computed: {
			inputType() {
				const type = this.type
				return type === 'password' ? 'text' : type
			}
		},
		methods: {
			clear() {
				this.$emit('input', '')
			},
			display() {
				this.showPassword = !this.showPassword
			},
			onFocus() {
				this.isFocus = true
			},
			onBlur() {
				this.$nextTick(() => {
					this.isFocus = false
				})
			},
			onInput(e) {
				this.$emit('input', e.detail.value)
			}
		}
	}
</script>

<style>
	.m-input-view {
		position: relative;
	}
	.m-input-input {
	/* 	flex: 1;
		width: 100%;
		min-height: 100%;
		line-height: inherit;
		background-color: rgba(0, 0, 0, 0); */
	}

	.m-input-icon {
		width:36rpx; height: 36rpx;display: block;float:right;margin-right: 20rpx;
	}
	.m-input-icon image{
		width:36rpx; height: 36rpx;display: block;float:right;
	}
	
	
	.ji{ width: 630rpx; height: auto;display: block;float:left;margin: 26rpx 60rpx 0rpx;}
	
	.ji_t{width: 100%; height: auto;display: block;float:left; font-size: 20rpx;color: #999999;margin: 0 0 10rpx 0;}
	
	.ji .input-row{width: 100%; height: 60rpx;display: block;float:left;border-bottom: 1px solid #DDDDDD; margin: 0 0 40rpx 0;}
	.ji .m-input-input {width: 80%; height: 40rpx;display: block;float:left; margin: 0 0 40rpx 0;font-size: 32rpx;color: #000000;}
	.ji .m-input-view{
		width: 100%; height: auto;display: block;float:left;
	}

</style>
